import { configureStore } from "@reduxjs/toolkit";
import {
  useSelector,
  useDispatch,
  TypedUseSelectorHook,
  shallowEqual,
} from "react-redux";
import counterReducer from "./feature/counter";
import homeReducer from "./feature/home";

const store = configureStore({
  reducer: {
    counter: counterReducer,
    home: homeReducer,
  },
});
type GetStateFnType = typeof store.getState;
// 获取store中的state类型
export type RootState = ReturnType<GetStateFnType>;

// useAppSelector的hook
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
export type DispatchType = typeof store.dispatch;
export const useAppDispatch: () => DispatchType = useDispatch;
export const shallowEqualApp = shallowEqual;
export default store;
